/*
 *  Copyright 2004 Blandware (http://www.blandware.com)
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.blandware.atleap.model.news;

import com.blandware.atleap.model.core.Page;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>Class that represents news item. News item is a special case of
 * {@link Page}. It has localized title, annotation, body and no other content
 * fields. Annotation contains a brief information, body contains full version.
 * </p>
 * <p>
 * When news item is active, it's available for users. For inactive news item
 * user will get HTTP 503 (Service Unavailable) error code when trying to view
 * it.
 * </p>
 * <p>
 * Two dates are assigned to each news item: publication date and expiration
 * date. When news item is created, it's made active if publication date is not
 * in future, else it becomes inactive. Then, when publication date comes, news
 * item is made active. Expiration date has a contrary effect: when it comes,
 * news item becomes inactive.
 * </p>
 * <p>Every News Item has a list of
 * {@link com.blandware.atleap.model.core.Role}s that are allowed to access it.
 * If that list is empty, everyone is allowed to access such News Item, otherwise
 * only users that have at least one role from that list can access the News Item.</p>
 * <p><a href="NewsItem.java.html"><i>View Source</i></a>
 * </p>
 * <p/>
 *
 * @author Sergey Zubtsovskiy <a href="mailto:sergey.zubtsovskiy@blandware.com">&lt;sergey.zubtsovskiy@blandware.com&gt;</a>
 * @version $Revision: 1.15 $ $Date: 2006/08/03 10:07:35 $
 * @struts.form include-all="false" extends="BaseForm" resetMappedProperties="false"
 * @hibernate.joined-subclass table="`al_news_item`" lazy="false"
 * @hibernate.joined-subclass-key column="`page_id`"
 */
public class NewsItem extends Page {

	//~ Instance variables

	/**
	 * Short annotation for this news item
	 */
	protected Map annotation = new HashMap();

	/**
	 * Full news item
	 */
	protected Map body = new HashMap();

	/**
	 * Publication date of news item
	 */
	protected Date publicationDate = new Date();

	/**
	 * Date when this item must be set inactive
	 */
	protected Date expirationDate;

	//~ Methods

	/**
     * Gets publication date of this news item. If the news item is created before
     * its publication date, it's made inactive; it will become active when
     * comes date of publication.
     *
	 * @return publication date
	 * @struts.form-field
	 * @struts.validator type="required, customdate"
	 * @struts.validator-args arg0resource="news.form.publicationDate"
	 * @hibernate.property column="`publication_date`" not-null="false" type="date"
	 */
	public Date getPublicationDate() {
		return publicationDate;
	}

    /**
     * Sets publication date of this news item. If the news item is created before
     * its publication date, it's made inactive; it will become active when
     * comes date of publication.
     *
     * @param publicationDate publication date
     */
	public void setPublicationDate(Date publicationDate) {
		this.publicationDate = publicationDate;
	}

	/**
     * Gets expiration date of this news item (it's the date when news item becomes
     * inactive)
     *
	 * @return expiration date
	 * @struts.form-field
	 * @struts.validator type="required, customdate"
	 * @struts.validator-args arg0resource="news.form.expirationDate"
	 * @hibernate.property column="`expiration_date`" not-null="false" type="date"
	 */
	public Date getExpirationDate() {
		return expirationDate;
	}

    /**
     * Sets expiration date of this news item (it's the date when news item becomes
     * inactive)
     *
     * @param expirationDate expiration date
     */
	public void setExpirationDate(Date expirationDate) {
		this.expirationDate = expirationDate;
	}

	// Internal field values

	/**
     * Gets annotations map
     *
	 * @return mapping from locale identifiers to annotations
	 * @struts.form-field
	 */
	public Map getAnnotation() {
		return annotation;
	}

    /**
     * Sets annotations map
     *
     * @param annotation mapping from locale identifiers to annotations
     */
	public void setAnnotation(Map annotation) {
		this.annotation = annotation;
	}

	/**
     * Gets bodies map
     *
	 * @return mapping from locale identifiers to bodies
	 * @struts.form-field
	 */
	public Map getBody() {
		return body;
	}

    /**
     * Sets bodies map
     *    
     * @param body mapping from locale identifiers to bodies
     */
	public void setBody(Map body) {
		this.body = body;
	}

}
